unit uSellectDollImage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TfSellectDollImage = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    MX, MY, MM, SI: Integer;
    Buffer: TBitMap;
  public
    { Public declarations }
  end;

var
  fSellectDollImage: TfSellectDollImage;

implementation

uses uEditItem;

{$R *.dfm}

procedure TfSellectDollImage.FormCreate(Sender: TObject);
begin
  Buffer  := TBitMap.Create;
end;

procedure TfSellectDollImage.FormDestroy(Sender: TObject);
begin
  Buffer.Free;
end;

procedure TfSellectDollImage.FormPaint(Sender: TObject);
begin
  Canvas.Draw(0, 0, Buffer);
end;

procedure TfSellectDollImage.FormMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  if (X >= 0) and (X <= (Buffer.Width)) then MX := X div 32;
  if (Y >= 0) and (Y <= Buffer.Height) then MY := Y div 32;
  MM := (MY * (Buffer.Width div 32)) + MX;
end;

procedure TfSellectDollImage.FormClick(Sender: TObject);
begin
  if (MM < 0) or (MM > 255) then Exit;
  fEditItem.DollID := MM;
  {
  case fEditItem.SlotBox.ItemIndex of
    0, 2, 11, 12: MM := MM + 256;
  end;
  fEditItem.ImageIndex := MM;
  frmMain.ItemsBitmaps[MM].Transparent := False;
  fEditItem.Image1.Canvas.Draw(0, 0, frmMain.ItemsBitmaps[MM]);
  frmImage.Image1.Canvas.Draw(0, 0, frmMain.ItemsBitmaps[MM]);
  }
  ModalResult := mrOK;
end;

procedure TfSellectDollImage.FormShow(Sender: TObject);
begin
  case fEditItem.SlotBox.ItemIndex of
    1: Buffer.LoadFromFile('data\images\top.bmp');
    3: Buffer.LoadFromFile('data\images\cloaks.bmp');
    4: Buffer.LoadFromFile('data\images\body.bmp');
    6: Buffer.LoadFromFile('data\images\boots.bmp');
    7: Buffer.LoadFromFile('data\images\gloves.bmp');
    8: Buffer.LoadFromFile('data\images\down.bmp');
    9: Buffer.LoadFromFile('data\images\right.bmp');
   10: Buffer.LoadFromFile('data\images\left.bmp');
   else Exit;
  end;
  ClientWidth  := Buffer.Width;
  ClientHeight := Buffer.Height;
end;

end.
